package controllers;

import models.Company;
import models.User;
import play.Logger;
import play.mvc.Controller;

import java.util.List;

public class Application extends Controller {

    public static void showLogin() {

        render();
    }

    public static void makeLogin(String user, String pass) {
        String view;
        if (User.find("byUserIdAndPassword", user, pass).first() != null)
            view = "Application/principal.html";
        else
            view = "errors/500.html";
        renderTemplate(view);
    }

    public static void goBackToPrincipal() {
        renderTemplate("Application/principal.html");
    }

    public static void registrarEmpresa() {

        render();
    }

    public static void saveCompany(String razonSocial, String propietario, String cliente, String description, String latitud, String longitud) {
        Company company = new Company(razonSocial, propietario, description, cliente, latitud, longitud);
        company.save();
        Logger.debug(company.toString());
        goBackToPrincipal();
    }

    public static void calcularRuta() {
        List<Company> listOfPropietaries = Company.find("byPropietario", "1").fetch();
        List<Company> listOfClients = Company.find("byCliente", "1").fetch();

        renderTemplate("Application/asignacionRuta.html", listOfPropietaries, listOfClients);
    }

    public static void generateOptimizeRoute() {
        render();
    }


}